<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Views/Shared/Iframe.Master" %>

<asp:Content ID="cJScripts" ContentPlaceHolderID="cphJScripts" runat="server">
    <script type="text/javascript">
        var mlength = 250;
        $(document).ready(function () {
            $("#comment").focus();
            $("#comment").keyup(function () {
                if ($(this).val().length > mlength) {
                    $(this).val($(this).val().substring(0, mlength));
                }
                $('#charRest').text($(this).val().length + ' / ' + mlength);
            });

            $(".blockButton .green").click(function () {
                $(this).addClass("loading");
                submit();
            })

            $(".blockButton .blue").click(function(){
                reset();
            })
        })

        function reset() {
            $('#contentPage form')[0].reset();
            $('#charRest').text($("#comment").val().length + ' / ' + mlength);
        }

        function submit() {
            $(".loader").show();
            if ($("#comment").val() != "") {
                $.ajax({
                    type: "POST",
                    url: "/Photo/CreateComment",
                    data: {IID : <%= ViewData["IID"] %>, Comment : $("#comment").val() , SectionName : '<%= ViewData["SectionName"] %>' },
                    success: function (msg) {
                        parent.ReloadComment();
                        parent.$.fn.colorbox.close();
                        $(".loader").hide();
                    },
                    error: function () {
                        parent.$.fn.colorbox.close();
                        $(".loader").hide();
                    }
                });
            } else {
                parent.$.fn.colorbox.close();
                $(".loader").hide();
            }
        }
    </script>
</asp:Content>

<asp:Content ID="cMainContent" ContentPlaceHolderID="cphMainContent" runat="server">
<div id="contentPage">
    <% using (Html.BeginForm()) {%>
        <p>
            <%= Html.TextArea("comment", new { @class = "largeTextSpace", maxlength = "250" })%>
        </p>
        <div class="loader"></div>
        <span id="charRest"> 0 / 250 </span>
        <div class="loader"></div>

        <div class="blockButton">
        	<a class="mediumBtn green awesome" href="javascript:void(0);" title="<%= ScoutNET.Resources.Master_Button_Submit %>"><%= ScoutNET.Resources.Master_Button_Submit %></a>
            <a class="mediumBtn blue awesome" href="javascript:reset();" title="<%= ScoutNET.Resources.Master_Button_Reset %>"><%= ScoutNET.Resources.Master_Button_Reset %></a>
        </div>
    <% } %>
</div>
</asp:Content>

